
const tools = require('tools');

const whitelist = [
    '/api/user/login',
    '/api/systemPar',
    '/api/config',
    '/api/emailer/send',
]

module.exports = async (ctx, next) => {
    if (ctx.url.indexOf('/api') === 0) {
        if (whitelist.indexOf(ctx.url) >= 0) {
            await next();
        } else {
            if (tools.verificationToken(ctx.header.authorization)) {
                await next();
            } else {
                ctx.status = 403;
                ctx.body = {
                    code: 403,
                    message: '请先登录',
                };
            }
        }
    } else {
        await next();
    }
}